package com.lxl.view;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;

import com.lxl.model.BookUser;
import com.lxl.service.BookUserService;
import com.lxl.service.impl.BookUserServiceImpl;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Font;
import java.awt.Cursor;

/**
 * @author 刘星鹭
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2014年9月12日 下午3:33:34
 */

public class MergeBookUser extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField userno;
	private JTextField username;
	private JTextField password;
	private JLabel label_1;
	private JLabel label_2;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MergeBookUser frame = new MergeBookUser();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public MergeBookUser() {
		setFont(new Font("微软雅黑", Font.PLAIN, 12));
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				ViewBookUser.main(new String[1]);
			}
		});
		setTitle("图书管理系统");
		setBounds(100, 100, 450, 227);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		userno = new JTextField();
		userno.setBounds(188, 24, 223, 27);
		contentPane.add(userno);
		userno.setColumns(10);

		username = new JTextField();
		username.setColumns(10);
		username.setBounds(188, 61, 223, 27);
		contentPane.add(username);

		password = new JTextField();
		password.setColumns(10);
		password.setBounds(188, 98, 223, 27);
		contentPane.add(password);

		JButton btnNewButton = new JButton("修改用户");
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				String name = username.getText();
				String psw = password.getText();
				if (name.equals("") || psw.equals("")
						|| userno.getText().equals(""))
					JOptionPane.showMessageDialog(null, "请填写所有资料！");
				else {
					Integer uno = Integer.parseInt(userno.getText());
					BookUserService bookUserService = new BookUserServiceImpl();
					bookUserService.merge(uno, new BookUser(name, psw));
					JOptionPane.showMessageDialog(null, "修改成功！");
				}
			}
		});
		btnNewButton.setBounds(172, 146, 93, 23);
		contentPane.add(btnNewButton);

		JLabel label = new JLabel("请输入欲修改资料的用户账号：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label.setBounds(16, 30, 183, 15);
		contentPane.add(label);

		label_1 = new JLabel("请输入新用户姓名：");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_1.setBounds(75, 67, 124, 15);
		contentPane.add(label_1);

		label_2 = new JLabel("请输入新用户密码：");
		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label_2.setBounds(75, 104, 108, 15);
		contentPane.add(label_2);
	}
}
